package com.tpcpp.ssm.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.tpcpp.ssm.pojo.User;
import com.tpcpp.ssm.service.IUserService;

/**
 * 前端控制器
 * 
 * @author tanp
 * 
 */
@Controller
@RequestMapping("/user")
public class UserController {
	private static final Logger logger = Logger.getLogger(UserController.class);
	
	@Autowired
	private IUserService userService;

	/**
	 * 根据ID获取用户信息
	 * 
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/showUser")
	public String showUser(HttpServletRequest request, Model model) {
		logger.info("－－－－－－－根据用户ＩＤ获取用户信息 showUser－－－－－－start----");
		int userId = Integer.parseInt(request.getParameter("id"));
		logger.info("－－－－－－－根据用户ＩＤ获取用户信息showUser－－－－－－请求数据id="+userId);
		User user = this.userService.getUserById(userId);
		if(user!=null){
			logger.info("－－－－－－－根据用户ＩＤ获取用户信息showUser－－－－－－返回结果="+JSON.toJSONString(user));
		}
		model.addAttribute("user", user);
		logger.info("－－－－－－－根据用户ＩＤ获取用户信息showUser－－－－－－end----");
		return "showUser";
	}
}
